package com.ahtcm.tcmlearning.utils.generateQustion;

import com.ahtcm.tcmlearning.dataObject.generateQuestion.GenerateQuestion;
import com.ahtcm.tcmlearning.model.Prescription;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PrescriptionQuestionGenerateUtil {
    private static String prescriptionQuestionTitle1 = "的组成，下列选项正确的是？";//getPrescriptionForm   questionId:1
    private static String prescriptionQuestionTitle2 = "的用法，下列选项正确的是？";//getPrescriptionUsage   questionId:2
    private static String prescriptionQuestionTitle3 = "的功用为？";//getPrescriptionEffect  questionId:3
    private static String prescriptionQuestionTitle4 = "的主要组成为？";//getPrescriptionMajor  questionId:4
    private static String prescriptionQuestionTitle5 = "的方解为？";//getPrescriptionAnalysis   questionId:5
    private static String prescriptionQuestionTitle6 = "的临床应用，下列说法正确的是？";//getPrescriptionApplication  questionId:6
    public static List<GenerateQuestion> generate(List<Prescription> optionPrescription, Prescription rightOption) {
        List<GenerateQuestion> list = new ArrayList<>();
        GenerateQuestion question1 = setPrescriptionValue(optionPrescription, rightOption, prescriptionQuestionTitle1, 1);
        GenerateQuestion question2 = setPrescriptionValue(optionPrescription, rightOption, prescriptionQuestionTitle2, 2);
        GenerateQuestion question3 = setPrescriptionValue(optionPrescription, rightOption, prescriptionQuestionTitle3, 3);
        GenerateQuestion question4 = setPrescriptionValue(optionPrescription, rightOption, prescriptionQuestionTitle4, 4);
        GenerateQuestion question5 = setPrescriptionValue(optionPrescription, rightOption, prescriptionQuestionTitle5, 5);
        GenerateQuestion question6 = setPrescriptionValue(optionPrescription, rightOption, prescriptionQuestionTitle6, 6);
        list.add(question1);
        list.add(question2);
        list.add(question3);
        list.add(question4);
        list.add(question5);
        list.add(question6);
        Collections.shuffle(list);
        return list;
    }

    private static GenerateQuestion setPrescriptionValue(List<Prescription> optionPrescription, Prescription rightOption, String prescriptionQuestionTitle, int questionId) {
        prescriptionQuestionTitle = rightOption.getPrescriptionName() + prescriptionQuestionTitle;
        System.out.println(prescriptionQuestionTitle);
        Collections.shuffle(optionPrescription);
        int rightIndex1 = optionPrescription.indexOf(rightOption);
        GenerateQuestion question = new GenerateQuestion();
        question.setTitle(prescriptionQuestionTitle);
        question.setAnswerIndex(rightIndex1 + 1);
        if (questionId == 1) {
            if (optionPrescription.size() == 1) question.setChoiceA(optionPrescription.get(0).getPrescriptionForm());
            else if (optionPrescription.size() == 2) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionForm());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionForm());
            } else if (optionPrescription.size() == 3) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionForm());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionForm());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionForm());
            } else {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionForm());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionForm());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionForm());
                question.setChoiceD(optionPrescription.get(3).getPrescriptionForm());
            }
        }
        if (questionId == 2) {
            if (optionPrescription.size() == 1) question.setChoiceA(optionPrescription.get(0).getPrescriptionUsage());
            else if (optionPrescription.size() == 2) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionUsage());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionUsage());
            } else if (optionPrescription.size() == 3) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionUsage());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionUsage());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionUsage());
            } else {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionUsage());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionUsage());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionUsage());
                question.setChoiceD(optionPrescription.get(3).getPrescriptionUsage());
            }
        }
        if (questionId == 3) {
            if (optionPrescription.size() == 1) question.setChoiceA(optionPrescription.get(0).getPrescriptionEffect());
            else if (optionPrescription.size() == 2) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionEffect());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionEffect());
            } else if (optionPrescription.size() == 3) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionEffect());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionEffect());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionEffect());
            } else {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionEffect());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionEffect());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionEffect());
                question.setChoiceD(optionPrescription.get(3).getPrescriptionEffect());
            }
        }
        if (questionId == 4) {
            if (optionPrescription.size() == 1) question.setChoiceA(optionPrescription.get(0).getPrescriptionMajor());
            else if (optionPrescription.size() == 2) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionMajor());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionMajor());
            } else if (optionPrescription.size() == 3) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionMajor());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionMajor());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionMajor());
            } else {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionMajor());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionMajor());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionMajor());
                question.setChoiceD(optionPrescription.get(3).getPrescriptionMajor());
            }
        }
        if (questionId == 5) {
            if (optionPrescription.size() == 1) question.setChoiceA(optionPrescription.get(0).getPrescriptionAnalysis());
            else if (optionPrescription.size() == 2) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionAnalysis());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionAnalysis());
            } else if (optionPrescription.size() == 3) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionAnalysis());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionAnalysis());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionAnalysis());
            } else {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionAnalysis());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionAnalysis());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionAnalysis());
                question.setChoiceD(optionPrescription.get(3).getPrescriptionAnalysis());
            }
        }
        if (questionId == 6) {
            if (optionPrescription.size() == 1) question.setChoiceA(optionPrescription.get(0).getPrescriptionApplication());
            else if (optionPrescription.size() == 2) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionApplication());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionApplication());
            } else if (optionPrescription.size() == 3) {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionApplication());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionApplication());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionApplication());
            } else {
                question.setChoiceA(optionPrescription.get(0).getPrescriptionApplication());
                question.setChoiceB(optionPrescription.get(1).getPrescriptionApplication());
                question.setChoiceC(optionPrescription.get(2).getPrescriptionApplication());
                question.setChoiceD(optionPrescription.get(3).getPrescriptionApplication());
            }
        }
        return question;

    }
}